from flask_wtf import FlaskForm
from flask_wtf.file import FileRequired, FileSize, FileAllowed
from wtforms.fields.numeric import IntegerField
from wtforms.fields.simple import StringField, FileField
from wtforms.validators import DataRequired, NumberRange
from marshmallow import Schema, fields, pre_dump

from src.entity.upload_entity import ALLOW_AUDIO_EXTENSION
from src.model import User


class UserSchema(FlaskForm):
    userName = StringField('userName', validators=[
        DataRequired("ユーザー名やパスワードを空にすることはログインできません")
    ])
    passWord= StringField('passWord', validators=[
        DataRequired("ユーザー名やパスワードを空にすることはログインできません")
    ])


class UserSchemaResp(Schema):
        user_id=fields.Integer(dump_default=0)
        user_name=fields.String(dump_default="")
        created_at = fields.Integer(default=0)
        updated_at = fields.Integer(default=0)
        @pre_dump
        def process_data(self, data: User, **kwargs):
            return {
                "user_id": data.user_id,
                "user_name": data.username,
                "created_at": int(data.created_at.timestamp()),
                "updated_at": int(data.updated_at.timestamp())
            }